package com.mrzhou.web.resolver;


import com.mrzhou.core.tool.api.CloudUser;
import com.mrzhou.web.util.WebUtil;
import org.springframework.core.MethodParameter;
import org.springframework.web.bind.support.WebDataBinderFactory;
import org.springframework.web.context.request.NativeWebRequest;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.method.support.ModelAndViewContainer;

public class TokenArgumentResolver implements HandlerMethodArgumentResolver {

    /**
     * 入参筛选
     * @param methodParameter 参数集合
     * @return
     */
    @Override
    public boolean supportsParameter(MethodParameter methodParameter) {
        return methodParameter.getParameterType().equals(CloudUser.class);
    }

    /**
     * 返回的参数
     * @param methodParameter 入参集合
     * @param modelAndViewContainer model and view
     * @param nativeWebRequest  web相关
     * @param webDataBinderFactory 入参解析
     * @return
     * @throws Exception
     */
    @Override
    public Object resolveArgument(MethodParameter methodParameter, ModelAndViewContainer modelAndViewContainer, NativeWebRequest nativeWebRequest, WebDataBinderFactory webDataBinderFactory) throws Exception {
        return WebUtil.getUser();
    }

}
